package com.edu.processor;

import com.edu.service.handler.LogHandler;
import com.edu.service.impl.BookServiceImpl;
import com.edu.service.impl.BookServiceProxy;
import com.edu.service.impl.UserServiceImpl;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

import java.lang.reflect.Proxy;

public class MyBeanPostProcessor implements BeanPostProcessor {

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if(bean.getClass() == UserServiceImpl.class  || bean.getClass() == BookServiceImpl.class){//确定了连接点
            return Proxy.newProxyInstance(bean.getClass().getClassLoader(), bean.getClass().getInterfaces(),new LogHandler(bean));
        }
        return bean;
    }
}
